#include <stdio.h>
#include <sys/wait.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>

int main()
{
    pid_t pid = fork();
    if(pid == 0)
    {
        printf("[Child] pid is %d\n", getpid());
        sleep(10);
    }
    else if(pid > 0)
    {
        printf("[Parent] Kill child after 2s...\n");
        sleep(2);
        kill(pid, SIGKILL);
        int status;
        waitpid(pid, &status, 0);
        if(WIFSIGNALED(status))
        {
            printf("[Parent] Child %d killed by signal %d\n", pid, WTERMSIG(status));
        }
    }
    else
    {
        perror("fork failed");
        exit(1);
    }
    return 0;
}

